let ss = (key, value) => {
  if (value) {
    ss.set(key, value)
  } else {
    return ss.get(key)
  }
}
ss.get = key => {
  let data = JSON.parse(sessionStorage[key])
  switch (true) {
    case data.type === 'Number':
      return parseFloat(data.data)
    case data.type === 'Object':
      return JSON.parse(data.data)
    case data.type === 'Array':
      return JSON.parse(data.data)
    default:
      return data.data
  }
}
ss.set = (key, value) => {
  let data = ss.$type(value)

  sessionStorage.setItem(key, JSON.stringify(data))
}
ss.$type = data => {
  let obj = {}
  let gettype = Object.prototype.toString
  switch (true) {
    case gettype.call(data) === '[object Number]':
      obj = {
        type: 'Number',
        data: String(data)
      }
      break
    case gettype.call(data) === '[object Object]':
      obj = {
        type: 'Object',
        data: JSON.stringify(data)
      }
      break
    case gettype.call(data) === '[object Array]':
      obj = {
        type: 'Array',
        data: JSON.stringify(data)
      }
      break
    default:
      obj = {
        type: 'String',
        data: String(data)
      }
  }
  return obj
}
export default ss
